package com.z.common.base;

import java.io.Serializable;
import java.util.List;

public class Results<T> implements Serializable {
    int count;
    Integer code;
    String msg;
    Object data;

    public Results() {
    }

    public Results(Integer code, String msg) {
        this.code = code;
        this.msg = msg;
    }

    public Results(int count, Integer code, String msg, Object datas) {
        this.count = count;
        this.code = code;
        this.msg = msg;
        this.data = datas;
    }

    /*无数据返回*/
    public static <T> Results<T> success() {
        return new Results<T>(ResponseCode.success.getCode(), ResponseCode.success.getMsg());
    }
    public static <T> Results<T> success(String msg) {
        return new Results<T>(ResponseCode.success.getCode(), msg);
    }
    public static <T> Results<T> success(ResponseCode responseCode) {
        return new Results<T>(responseCode.getCode(), responseCode.getMsg());
    }
    /*单数据返回*/
    public static <T> Results<T> success(T data) {
        return new Results<T>(0, ResponseCode.success.getCode(), ResponseCode.success.getMsg(), data);
    }
    public static <T> Results<T> success(String msg, T data) {
        return new Results<T>(0, ResponseCode.success.getCode(), msg, data);
    }
    public static <T> Results<T> success(ResponseCode responseCode, T data) {
        return new Results<T>(0, responseCode.getCode(), responseCode.getMsg(), data);
    }

    /*多数据返回*/
    public static <T> Results<T> success(Integer count, Object datas) {
        return new Results<T>(count, ResponseCode.table_success.getCode(), ResponseCode.success.getMsg(), datas);
    }
    public static <T> Results<T> success(Integer count, String msg, Object datas) {
        return new Results<T>(count, ResponseCode.table_success.getCode(), msg, datas);
    }
    public static <T> Results<T> success(Integer count, ResponseCode responseCode, List<T> datas) {
        return new Results<T>(count, responseCode.getCode(), responseCode.getMsg(), datas);
    }

    /*失败返回*/
    public static <T> Results<T> failure(){
        return new Results<T>(ResponseCode.error.getCode(), ResponseCode.error.getMsg());
    }
    public static <T> Results<T> failure(ResponseCode responseCode) {
        return new Results<T>(responseCode.getCode(), responseCode.getMsg());
    }
    public static <T> Results<T> failure(Integer code, String msg){
        return new Results<T>(code, msg);
    }

    public int getCount() {
        return count;
    }

    public void setCount(int count) {
        this.count = count;
    }

    public Integer getCode() {
        return code;
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public Object getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }
}
